from generator.plain_class_name import PlainClassName

class PlainClassWriter(object):
	def __init__(self, path, table_desc):
		self.path = path
		self.table_desc = table_desc

	def write(self):
		file_name_with_path = '{}{}.py'.format(self.path, self.get_file_name())
		with open(file_name_with_path, 'w') as f:
			self.write_class_head(f)
			self.write_init_function(f)
			self.write_class_body(f)
			f.flush()
		
	def write_class_head(self, f):
		f.write('#This file is generated by program. DO NOT EDIT IT MANUALLY!\n')
		self.write_import_declaration(f)
		f.write('class {}(object):\n'.format(self.get_class_name()))

	def write_import_declaration(self, f):
		f.write('import protocol.auto_data_pb2\n\n')

	def write_init_function(self):
		pass
	
	def write_class_body(self, f):
		pass

	def write_to_net_function(self, f):
		self.write_to_net_head(f)
		self.write_to_net_body(f)

	def write_to_net_head(self, f):
		f.write('\tdef to_net(self):\n')

	def write_to_net_body(self, f):
		pass

	def write_to_net_string_function(self, f):
		f.write('\tdef to_net_string(self):\n')
		f.write('\t\treturn self.to_net().SerializeToString()\n\n')

	def get_file_name(self):
		plain_class_name = PlainClassName()
		return plain_class_name.get_file_name(self.table_desc['table_name'])
	
	def get_class_name(self):
		pass
	
